package com.ponhu.ea2.support.validation.annotions;

import com.ponhu.ea2.support.validation.validator.ExpressionValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 表达式校验注解
 * @author Wang
 * @date 2021/10/20 5:15 下午
 */
@Target({TYPE})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {ExpressionValidator.class})
public @interface ValidateExpression {
    // 默认错误消息
    String message() default "必须符合表达式条件";;

    /**
     * SPEL表达式
     * @return
     */
    String expression();

    // 分组
    Class<?>[] groups() default {};

    // 负载
    Class<? extends Payload>[] payload() default {};

    // 指定多个时使用
    @Target({TYPE})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        ValidateExpression[] value();
    }

}
